let Activities = require('../model/Activities');
let printLog = require('../log4j-config');
module.exports = function (req, res) {
    //这个地方不去判断aid在数据库里是否存在，直接交给catch去处理错误
    Activities.destroy({
        where : {aid : req.params.aid}
    }).then(function(numbers) {
        if(numbers > 0) {
            printLog.INFO(`DELETE an activity(aid = ${req.params.aid}) at IP : ${req.host}` )
            res.send({
                succeed : true,
                lines : numbers
            });
        }
        else {
            throw {
                msg : 'no such activity'
            }
        }
    }).catch(function(err) {
        printLog.ERROR(`ERROR on DELETE an activity(aid = ${req.params.aid}) at IP : ${req.host}` )
        res.status(400).send({succeed : false, err : err});
    });
}